package com.zbf.task.tasks;

import com.alibaba.fastjson.JSON;
import com.zbf.task.mapper.TestOrderMapper;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author: LCG
 * 作者: LCG
 * 日期: 2021/3/12  15:09
 * 描述: 定时任务 处理订单发送是MQ的失败的消息
 */
@Component
public class TestOrderHandler {

    @Autowired
    TestOrderMapper testOrderMapper;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Scheduled(cron = "0/2 * * * * ?")
    public void orderUnSendHandler(){

        List<Map<String, Object>> unSendMsg = testOrderMapper.getUnSendMsg();
        for (Map<String, Object> map : unSendMsg) {

            System.out.println("=========执行任务========="+unSendMsg);

            String orderMs1 = map.get("orderMs").toString();
            CorrelationData correlationData=new CorrelationData();
            Message message=new Message(orderMs1.getBytes(),null);
            correlationData.setReturnedMessage(message);

            rabbitTemplate.convertAndSend("MY-EXCHANGE","ZHI-LIAN",orderMs1,correlationData);



        }
    }

}
